--
-- Author:      feilong
-- DateTime:    2019-10-30 10:59:15
-- Description: 节点中用户信息

local ServerType = require("ServerType")

local table_insert = table.insert
local table_remove = table.remove

local User = class("User")

function User:ctor(user_id)
    self.user_id = user_id or 0 --玩家id
    self.type = 0		 --      
    self.user_name  = "" 	 --玩家名
    self.fd = nil 	--socket fd
    self.service = nil --所在的服务
    self.gate_server = nil --所在网关节点
    self.hall_server = nil --所在大厅节点	
    self.node_server = nil --
    self.game_server = nil --所在游戏节点    

    self.server_list = {}
end

function User:setData(data)
    for k, v in pairs(data) do 
    	self[k] = v
    end
end

function User:getData()
	local data = {}
	data.user_id = self.user_id
	data.type = self.type
	data.user_name = self.user_name
	data.fd = self.fd
	data.service = self.service

	data.gate_server = self.gate_server
	data.hall_server = self.hall_server
	data.node_server = self.node_server
	data.game_server = self.game_server	
	return data
end

function User:getUserId()
	return self.user_id
end

function User:getType()
	return self.type
end

function User:getName()
	return self.name
end

function User:getGateServer()
	return self.gate_server
end

function User:getHallServer()
	return self.hall_server
end

function User:getNodeServer()
	return self.node_server
end

function User:getGameServer()
	return self.game_server
end

function User:getServerByType(server_type)
	if server_type == ServerType.GATE then 
		return self:getGateServer()
	elseif server_type == ServerType.HALL then
		return self:getHallServer()
	elseif server_type == ServerType.GAME then 
		return self:getGameServer()
	elseif server_type == ServerType.NODE then
		return self:getNodeServer()
	end
	return
end

function User:getFD()
	return self.fd
end

function User:getServerList()
	return {
	    self.gate_server,
	    self.hall_server,
	    self.node_server,
	    self.game_server,
	}
end


return User